package com.kaki;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * @author Kaki Nakajima
 * @Date 2019-08-26
 * @Desc 扫描结果提示框
 */
public class AlertFrame implements ActionListener {

    public static void alert(String resultStr) throws MalformedURLException {

        JFrame window1 = new JFrame("结果");

        //初始化容器
        Container container = window1.getContentPane();
        container.setBackground(new Color(204,238,200));

        URL imgUrl = new URL("https://portrait.gitee.com/uploads/avatars/user/1720/5160819_kakiNakajima_1578981461.png!avatar60");
        ImageIcon icon = new ImageIcon(imgUrl);
        window1.setIconImage(icon.getImage());
        window1.setBounds(60,100,700,520);
        window1.setVisible(true);
        window1.setLayout(null);

        //标题组
        JLabel lable_username = new JLabel("检测结果（返回请点击x）");
        lable_username.setFont(new Font("111", 1, 20));
        JButton cfam = new JButton("请点击x");
        cfam.setBackground(Color.magenta);

        //盒子组
        Box userInputBox = Box.createVerticalBox();
        Box buttonBox = Box.createHorizontalBox();
        Box usernameBox = Box.createHorizontalBox();
        Box passWrodBox = Box.createHorizontalBox();
        usernameBox.add(lable_username);
        usernameBox.add(Box.createHorizontalStrut(10));

        //文本域
        JTextArea textArea = new JTextArea();
        textArea.setText(resultStr);

        //文本域盒子
        userInputBox.add(usernameBox);
        userInputBox.add(Box.createHorizontalStrut(102));
        userInputBox.add(new JScrollPane(){
           @Override
           public Dimension getPreferredSize(){
               return new Dimension(1330,600);
           }
        }.add(textArea));
        userInputBox.add(passWrodBox);


        //按钮盒子
        buttonBox.add(Box.createHorizontalStrut(10));
        buttonBox.add(cfam);

        //页面位置
        userInputBox.setBounds(34,20, 600, 440);
        buttonBox.setBounds(265, 200, 400, 100);

        //总容器
        window1.add(userInputBox);
        window1.setDefaultCloseOperation(2);
        window1.validate();
    }

    public void actionPerformed(ActionEvent e) {

    }
}
